package com.cls.business.controller;
import com.baomidou.mybatisplus.core.toolkit.StringPool;
import com.cls.common.annotation.ControllerEndpoint;
import com.cls.common.utils.MyUtil;
import com.cls.common.entity.MyConstant;
import com.cls.common.controller.BaseController;
import com.cls.common.entity.QueryRequest;
import com.cls.common.entity.ResponseVO;
import com.github.pagehelper.PageInfo;
import com.cls.business.entity.MemberInfoRecord;
import com.cls.business.service.IMemberInfoRecordService;
import com.wuwenze.poi.ExcelKit;
import lombok.extern.slf4j.Slf4j;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.PathVariable;
import org.apache.shiro.authz.annotation.RequiresPermissions;
import org.springframework.stereotype.Controller;
import org.springframework.validation.annotation.Validated;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.ResponseBody;
import org.springframework.ui.Model;
import javax.servlet.http.HttpServletResponse;
import javax.validation.Valid;
import java.util.List;

/**
 * 委托课题审核成员变动记录信息表 Controller
 *
 * @author slx
 * @date 2020-12-02 14:27:30
 */
@Slf4j
@Validated
@Controller
@RequiredArgsConstructor
public class MemberInfoRecordController extends BaseController {

    private final IMemberInfoRecordService memberInfoRecordService;

    /**
    * 委托课题审核成员变动记录信息表列表页面
    **/
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/memberInfoRecord")
    public String memberInfoRecordIndex(){
        return MyUtil.view("business/memberInfoRecord/memberInfoRecord");
    }

    /**
    * 委托课题审核成员变动记录信息表新增页面
    * @return
    */
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/memberInfoRecord/memberInfoRecordAdd")
    public String memberInfoRecordAdd(Model model){
        return MyUtil.view("business/memberInfoRecord/memberInfoRecordAdd");
    }

    /**
    * 委托课题审核成员变动记录信息表修改页面
    * @return
    */
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/memberInfoRecord/memberInfoRecordUpdate/{memberInfoRecordId}")
    public String memberInfoRecordUpdate(@PathVariable Long memberInfoRecordId, Model model){
        MemberInfoRecord memberInfoRecord = memberInfoRecordService.getById(memberInfoRecordId);
        model.addAttribute("memberInfoRecord",memberInfoRecord);
        return MyUtil.view("business/memberInfoRecord/memberInfoRecordUpdate");
    }



    /**
    * 委托课题审核成员变动记录信息表详情页面
    * @return
    */
    @GetMapping(MyConstant.VIEW_PREFIX + "biz/memberInfoRecord/memberInfoRecordDetail/{memberInfoRecordId}")
    public String memberInfoRecordDetail(@PathVariable Long memberInfoRecordId, Model model){
        MemberInfoRecord memberInfoRecord = memberInfoRecordService.getById(memberInfoRecordId);
        model.addAttribute("memberInfoRecord",memberInfoRecord);
        return MyUtil.view("business/memberInfoRecord/memberInfoRecordDetail");
    }

    @GetMapping("memberInfoRecord")
    @ResponseBody
    @RequiresPermissions("memberInfoRecord:list")
    public ResponseVO getAllMemberInfoRecords(MemberInfoRecord memberInfoRecord) {
        return ResponseVO.success(memberInfoRecordService.findMemberInfoRecords(memberInfoRecord));
    }

    @GetMapping("memberInfoRecord/list")
    @ResponseBody
    @RequiresPermissions("memberInfoRecord:list")
    public ResponseVO memberInfoRecordList(QueryRequest request, MemberInfoRecord memberInfoRecord) {
        PageInfo<MemberInfoRecord> pageInfo =  this.memberInfoRecordService.findMemberInfoRecords(request, memberInfoRecord);
        return ResponseVO.success(pageInfo);
    }

    @ControllerEndpoint(operation = "新增MemberInfoRecord", exceptionMessage = "新增MemberInfoRecord失败")
    @PostMapping("memberInfoRecord")
    @ResponseBody
    @RequiresPermissions("memberInfoRecord:add")
    public ResponseVO addMemberInfoRecord(@Valid MemberInfoRecord memberInfoRecord) {
        this.memberInfoRecordService.createMemberInfoRecord(memberInfoRecord);
        return ResponseVO.success();
    }

    @ControllerEndpoint(operation = "多个删除MemberInfoRecord", exceptionMessage = "删除MemberInfoRecord失败")
    @PostMapping("memberInfoRecord/deletes/{ids}")
    @ResponseBody
    @RequiresPermissions("memberInfoRecord:delete")
    public ResponseVO deleteMemberInfoRecords(@PathVariable String ids) {
        String[] idArry = ids.split(StringPool.COMMA);
        this.memberInfoRecordService.deleteMemberInfoRecords(idArry);
        return ResponseVO.success();
    }


    @ControllerEndpoint(operation = "删除单个MemberInfoRecord", exceptionMessage = "删除MemberInfoRecord失败")
    @PostMapping("memberInfoRecord/delete/{memberInfoRecordId}")
    @ResponseBody
    @RequiresPermissions("memberInfoRecord:delete")
    public ResponseVO deleteMemberInfoRecord(@PathVariable Long memberInfoRecordId) {
        this.memberInfoRecordService.removeById(memberInfoRecordId);
        return ResponseVO.success();
    }

    @ControllerEndpoint(operation = "修改MemberInfoRecord", exceptionMessage = "修改MemberInfoRecord失败")
    @PostMapping("memberInfoRecord/update")
    @ResponseBody
    @RequiresPermissions("memberInfoRecord:update")
    public ResponseVO updateMemberInfoRecord(MemberInfoRecord memberInfoRecord) {
        this.memberInfoRecordService.updateMemberInfoRecord(memberInfoRecord);
        return ResponseVO.success();
    }

    @ControllerEndpoint(operation = "修改MemberInfoRecord", exceptionMessage = "导出Excel失败")
    @PostMapping("memberInfoRecord/excel")
    @ResponseBody
    @RequiresPermissions("memberInfoRecord:export")
    public void export(QueryRequest queryRequest, MemberInfoRecord memberInfoRecord, HttpServletResponse response) {
        List<MemberInfoRecord> memberInfoRecords = this.memberInfoRecordService.findMemberInfoRecords(queryRequest, memberInfoRecord).getList();
        ExcelKit.$Export(MemberInfoRecord.class, response).downXlsx(memberInfoRecords, false);
    }
}
